<?php
namespace Tools\Controller;
use Common\Controller\AdminbaseController;

/**
 * 留言板后台
 */
class AdminGuestbookController extends AdminbaseController{

	protected $guestbook_model;

	public function _initialize() {
		parent::_initialize();
		$this->guestbook_model=D("Common/ToolsGuestbook");
	}

	// 后台留言列表
	public function index(){
		$count=$this->guestbook_model->count();
		$page = $this->page($count, 20);
		$guestmsgs=$this->guestbook_model->order(array("createtime"=>"DESC"))->limit($page->firstRow . ',' . $page->listRows)->select();
		$this->assign("page", $page->show('Admin'));
		$this->assign("guestmsgs",$guestmsgs);
		$this->display();
	}
	//ajax修改审核状态
	public function ajax_status(){
			$model=M("tools_guestbook");
			// 更新数据
			if ($model->save($_POST)) {
				echo "1";
			}else{
				echo "0";
			}
		}
		// 留言内容插入数据
	public function inserts(){

		$models=M("tools_guestbook");
		$id=$_POST[id];
		// dump($_POST);
		// exit;
		// $data=array();
		$data['reply']=$_POST['reply'];
		// $data['ztime']=time();
		// 进行数据插入
		// $models->reply=$_POST['reply'];
		$where = array('id'=>$id);
		$models->where($where)->save($data);
		// echo $models->getLastSql();
		// exit;
		if ($models->where($where)->save($data) !== false) {

			 $this->success("回复成功");
		}else{
			echo "666";
			exit;
			 $this->error("回复失败");
		}
	}

	// 删除留言
	public function delete(){
		$id=I("get.id",0,'intval');

		$result=$this->guestbook_model->where(array("id"=>$id))->delete();
		if($result!==false){
			$this->success("删除成功！", U("AdminGuestbook/index"));
		}else{
			$this->error('删除失败！');
		}
	}
	 public function add(){
	 	$this->display();
	 }
}